# -*- coding: utf-8 -*-

from functools import partial
from w.html.doctypes.preferable import Script, Input, Meta, Link, Style
from w.html.base import ITag

def esc(obj):
    return partial(obj, escapedContent=True)

def uesc(obj):
    return partial(obj, escapedContent=False)

JScript = partial(Script, htype='text/javascript')
TextInput = partial(Input, htype='text')
PasswdInput = partial(Input, htype='password')
HiddenInput = partial(Input, htype='hidden')
CheckInput = partial(Input, htype='checkbox')

def CSSLink(url):
    return partial(Link, hrel="stylesheet", htype="text/css", hhref=url)()

CSSArea = partial(Style, htype="text/css")

def CSSImport(url):
    return '@import url(%s);'%url

def CSSImportArea(cssList):
    return CSSArea([CSSImport(url) for url in cssList])

def MetaContent(charset):
    return Meta(hhttp__equiv="Content-Type", hcontent="text/html; charset=%s"%charset)

class TemplateTag(ITag):
    def __init__(self, contentFunc, *args, **kwargs):
        ITag.__init__(self)

        self.contentFunc = contentFunc
        self.args = args
        self.kwargs = kwargs
        for a in args:
            if isinstance(a, ITag):
                self.append(a)
        for a in kwargs.values():
            if isinstance(a, ITag):
                self.append(a)
    
    def make(self):
        return [self.contentFunc(*self.args,**self.kwargs)]
